﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using BLL.TcpUdp;
using System.Windows.Threading;
using BLL.Dataprogram;
using Framework.Kit;

namespace Client
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        /********全局变量*******/
        public static BLL.TcpUdp.Client client = new BLL.TcpUdp.Client(new Coder());
        public static string conn = AppOpr.GetConfigStrings("server_ip");
        public static ushort port = Convert.ToUInt16(AppOpr.GetConfigStrings("server_port"));
        public static ushort timespan = Convert.ToUInt16(AppOpr.GetConfigStrings("timespan"));
        public static bool islogin = false; //是否已登录
        public static int maxmoney = 1000;  //存在客户端的最高价
        public static string seatNum;       //座位号


        public static string BMname = "竞价销售交易会";              //拍卖会名
        public static string SBname = "2700吨自有贸易粮（小麦）";    //商品名称
        public static string JBfunction = "定时拍卖";                //竞拍方式 
        public static string BMtencher = "孙保祥 刘明军";            //拍卖师  
        public static string BMbegintime = "11月18日上午10时";       //开始时间
        public static int addmoney = 500;                            //递增金额
        public static string SP_spclass = "混合小麦";                //商品类型
        public static string SP_spmoney = "148,500元";               //拍卖底价
        public static string SP_spLV = "三等以上";                   //商品等级


        /********全局方法*******/

        /// <summary>
        /// 连接服务器,如果返回false证明一定连不上(最好不要用返回值)
        /// </summary>
        /// <returns>布尔</returns>
        public static bool connect()
        {
            try
            {
                if (App.client.Connect(App.conn, App.port))
                {
                    return true ;
                }
                else {
                    return false;
                }
            }
            catch (Exception ex)
            {
                other.WriteErrLog("判断服务器是否连接", ex);
                return false;
            }
        }

        /// <summary>
        /// 全局数据发送
        /// </summary>
        /// <param name="cmdType">commandType 对象</param>
        /// <param name="content">消息内容</param>
        public static void sendData(commandType cmdType, string content)
        {
            try
            {
                DataproAnaly da = new DataproAnaly();
                da.DataKey = "12345678";
                da.CmdType = cmdType;
                da.DataBody = content;
                App.client.Send(da.encodeData());
            }
            catch (Exception ex)
            {
                other.WriteErrLog("数据发送操作", ex);
            }
        }
    }
}
